package com.zust.zst.studentstatus.service.Impl;

import com.zust.zst.common.dto.studentstatus.*;
import com.zust.zst.common.vo.studentstatus.StudentInfoVO;
import com.zust.zst.common.vo.studentstatus.StudentUpdateVO;
import com.zust.zst.dao.mapper.studentstatus.StudentInfoManagementMapper;
import com.zust.zst.studentstatus.service.StudentInfoManagementService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 学生信息管理服务层实现类
 *
 * @author ldnb
 * @date 2022/11/24 16:09
 */
@Service("studentInfoManagementServiceImpl")
public class StudentInfoManagementServiceImpl implements StudentInfoManagementService {

    @Resource
    private StudentInfoManagementMapper studentInfoManagementMapper;

    @Override
    public List<String> getAllMajors(int uid) {
        return studentInfoManagementMapper.getAllMajors(uid);
    }

    @Override
    public List<String> getAllMajorClazzs(MajorToSelectClazzDTO majorDTO) {
        String major = majorDTO.getMajor();
        if (major == null || major.equals("")){
            major = "软件工程";
        }
        int majorId = studentInfoManagementMapper.getMajorIdByName(major);
        return studentInfoManagementMapper.getAllMajorClazzs(majorId);
    }

    @Override
    public int addStudent(int uid, AddStudentDTO addStudentDTO) {
        int collegeId = studentInfoManagementMapper.getCollegeIdByUid(uid);
        int majorId = studentInfoManagementMapper.getMajorIdByName(addStudentDTO.getMajor());
        int clazzId = studentInfoManagementMapper.getClazzIdByName(addStudentDTO.getClazz());
        return studentInfoManagementMapper.addStudent(collegeId, majorId, clazzId, addStudentDTO);
    }

    @Override
    public List<StudentInfoVO> getCollegeStudent(int uid, SearchCollegeStudentDTO dto) {
        //int page = dto.getPage() - 1;
        int page = (dto.getPage() - 1) * dto.getPageSize();
        dto.setPage(page);
        return studentInfoManagementMapper.getCollegeStudent(uid, dto);
    }

    @Override
    public int getTotalLineCollegeStudent(int uid) {
        return studentInfoManagementMapper.getTotalLineCollegeStudent(uid);
    }

    @Override
    public List<StudentInfoVO> getCollegeStudentByUidAndName(int uid, SearchCollegeStudentByUidAndNameDTO dto) {
        int page = (dto.getPage() - 1) * dto.getPageSize();
        dto.setPage(page);
        return studentInfoManagementMapper.getCollegeStudentByUidAndName(uid, dto);
    }

    @Override
    public int getTotalLineCollegeStudentByUidAndName(int uid, SearchTotalCollegeStudentByUidAndNameDTO dto) {
        return studentInfoManagementMapper.getTotalLineCollegeStudentByUidAndName(uid, dto);
    }

    @Override
    public int updateStudent(StudentUpdateVO studentUpdateVO) {
        return studentInfoManagementMapper.updateStudent(studentUpdateVO);
    }
}
